//
//  HNStrengtheningClassApplicationCell.m
//  优学荟管理系统
//
//  Created by edz on 2017/11/25.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "HNStrengtheningClassApplicationCell.h"
#import "HNStrengtheningClassApplicationApplyElementView.h" // 要素View
#import "HNStrengtheningClassApplicationCountView.h" // 统计View

@implementation HNStrengtheningClassApplicationCell
{
    __weak IBOutlet UILabel *_Title; // 标题
    __weak IBOutlet UILabel *_Name; // 名称
    __weak IBOutlet UILabel *_UserName; // 账号
    __weak IBOutlet UILabel *_State; // 状态
    __weak IBOutlet UIView *_ApplyView; // 要素View
    __weak IBOutlet NSLayoutConstraint *_ApplyViewHeight; // // 要素View高
    __weak IBOutlet UIView *_OrgView; // 统计表View
    __weak IBOutlet NSLayoutConstraint *_OrgViewHeight; // 统计表View高
    __weak IBOutlet NSLayoutConstraint *_ContentViewHeight;
    __weak IBOutlet UIButton *_StrengtheningClassListBtn;
}


- (void)setModel:(HNStrengtheningClassApplicationModel *)Model {
    
    _Model = Model;
    _Title.text = Model.name;
    _Name.text = Model.petName;
    _UserName.text = Model.username;
    _State.text = [Model.haveReinforce isEqualToNumber:@0] ? @"未开课" : @"已开课";
    _StrengtheningClassListBtn.hidden = [Model.haveReinforce isEqualToNumber:@0] ? YES : NO;
    
    // 设置要素的View
    [self SetupApplyViewOfModel:Model];
    
    // 设置统计表的View
    [self SetupCountViewOfModel:Model];
}

/** 设置要素的View */
- (void)SetupApplyViewOfModel:(HNStrengtheningClassApplicationModel *)Model {
    
    [Model.ApplyElementArr enumerateObjectsUsingBlock:^(HNStrengtheningApplicationApplyElementModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
       
        HNStrengtheningClassApplicationApplyElementView *View = [[HNStrengtheningClassApplicationApplyElementView alloc] initWithTitle:obj.content andNum:obj.count];
        [_ApplyView addSubview:View];
        [View mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(_ApplyView.mas_top).offset(40*idx);
            make.left.equalTo(_ApplyView.mas_left).offset(-12);
            make.right.equalTo(_ApplyView);
            make.height.equalTo(@40);
        }];
    }];
    _ApplyViewHeight.constant += (Model.ApplyElementArr.count * 40);
    _ContentViewHeight.constant += (_ApplyViewHeight.constant);
    [self layoutIfNeeded];
}

/** 设置统计表的View */
- (void)SetupCountViewOfModel:(HNStrengtheningClassApplicationModel *)Model {
    
    [Model.OrgElementArr enumerateObjectsUsingBlock:^(HNCourseListChartsModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
       
        HNStrengtheningClassApplicationCountView *View = [[HNStrengtheningClassApplicationCountView alloc] initWithNum:obj.commentCount andTitle:obj.content andCountNum:obj.totleCommentCount];
        [_OrgView addSubview:View];
        [View mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_OrgView.mas_top).offset(44*idx);
            make.left.equalTo(_OrgView.mas_left).offset(-12);
            make.right.equalTo(_OrgView);
            make.height.equalTo(@44);
        }];
    }];
    _OrgViewHeight.constant += (Model.OrgElementArr.count * 44);
    _ContentViewHeight.constant += (_OrgViewHeight.constant);
    [self layoutIfNeeded];
}


/** 删除 */
- (IBAction)Action_Delete:(UIButton *)sender {
    
    self.Delegate ? [self.Delegate HNStrengtheningClassApplicationCell:self ActionWithDelete:sender andModel:self.Model] : nil;
}

/** 增加加强课 */
- (IBAction)Action_AddStrengtheningClass:(UIButton *)sender {
    
    self.Delegate ? [self.Delegate HNStrengtheningClassApplicationCell:self ActionWithOpenStrengtheningClass:sender andModel:self.Model] : nil;
}

/** 加强课列表 */
- (IBAction)Action_List:(UIButton *)sender {
    
    self.Delegate ? [self.Delegate HNStrengtheningClassApplicationCell:self ActionWithStrengtheningClassList:sender andModel:self.Model] : nil;
}

@end
